﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using TBlog.Web.Models;
using TBlog.Web.Repository;
using TBlog.Web.ViewModel;
using TBlog.Web.Common.PageHelper;
namespace TBlog.Web.Service
{
    public class CategoryService : BaseService<Category>, ICategoryService
    {
        IRepository<Category> _repository;
        public CategoryService(IRepository<Category> repository)
            : base(repository)
        {
            _repository = repository;
        }

        public Common.PageHelper.PagedList<Category> GetCategory(System.Linq.Expressions.Expression<Func<Category, bool>> predicate, Common.PageHelper.PageListRequest pr)
        {

            var list = _repository.GetAll().ToPagedList(predicate, pr);
            return list;
        }
        public new Category GetByID(int id)
        {
            return _repository.GetByID(id);
        }

        public bool IsExists(string name)
        {
            var res = _repository.GetAll().Any(a => a.CategoryName == name);//.SingleOrDefault();
            return res;
        }
    }
}